<!DOCTYPE html>
<html>
<?php $this->load->view('admin/public/header.html');?>
<style>
	. space{padding:10px;}

</style>
<body class="childrenBody">
<form class="layui-form layui-row layui-col-space20" lay-filter="expert_form">
	<div class="layui-col-md6 layui-col-xs12 ">
		<div class="layui-row layui-col-space10">
			<div class="layui-col-md12 layui-col-xs7">
				<div class="layui-form-item magt3">
					<div class="layui-row layui-col-space10">
						<div class="layui-col-md12 layui-col-xs6">
							<label class="layui-form-label">图片</label>
							<div class="layui-upload-list thumbBox posterBox mag0 magt3">
								<img class="layui-upload-img thumbImg posterimg"  src="<?php echo isset($bannerInfo['imagePath'])?IMAGEHOST.@$bannerInfo['imagePath']:'';?>">
								<input type="hidden" class="poster" lay-verify="required" value="<?php echo @$bannerInfo['imagePath']?>" name="imagePath">
							</div>
						</div>
					</div>
				</div>
				<div class="layui-form-item magt3">
					<label class="layui-form-label">图片名称</label>
					<input type="hidden" class="expertId" name="bannerId" value="<?php echo @$bannerInfo['bannerId']?>">
					<div class="layui-input-block">
						<input type="text" class="layui-input name" name="bannerName" value="<?php echo @$bannerInfo['bannerName']?>" lay-verify="required" placeholder="请输入图片名称">
					</div>
				</div>
				
				
			</div>
			<div class="layui-right">
				<a class="layui-btn " lay-submit  lay-filter="bannerSubmit">保存</a>
			</div>
			
		</div>
	</div>
	
</form>
<script type="text/javascript">
var path='/public/appeditor/';
layui.config({
	base : path
}).extend({
	"appeditor" : "appeditor"
})
layui.use(['form','layer','layedit','laydate','upload',],function(){
	
	
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        laypage = layui.laypage,
        upload = layui.upload,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;


    
    var layerindex;		//弹层句柄
    //上传缩略图
    upload.render({
        elem: '.posterBox',
        //multiple:true,
        url: '<?php echo site_url("upload/upload")?>',
        before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
        	layerindex=layer.load(); //上传loading
        },
        done: function(res, index, upload){
        	console.log(1);
        	layer.close(layerindex);
            if(res.code==200){
            	layer.msg('上传成功');
            	var url=res.content.url
            	var src='<?php echo IMAGEHOST?>'+url;
            	$('.posterimg').attr('src',src);
                $('.thumbBox').css("background","#fff"); 
                $(".poster").val(url);
            }else{
            	layer.msg('上传失败');
            }
        }
    });
    
    
    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    
    

	form.verify({
        required : function(val,dom){
        	var name=($(dom).attr('name'));
        	var tips='必填项';
        	switch (name) {
			case 'bannerName':
				tips='图片名称'
				break;
			case 'imagePath':
				tips='图片'
				break;
			case 'listId':
				tips='资讯条目'
				break;
			
			
			default:
				break;
			}
            if(val == ''){
                return tips+"不能为空";
            }
        },
        
        

    })
    
    form.on("submit(bannerSubmit)",function(data){    	
    
    	var index=layer.load();
        $.ajax({
        	type:'post',
        	data:data.field,
        	url:'<?php echo site_url("admin/banner/save")?>',
        	dataType: "json", 
        	success:function(res){
        		//console.log(res.code);return;
        		if(res.code==200){
        			top.layer.close(index);
                    top.layer.msg("操作成功！");
                    //刷新父页面
                    //parent.location.reload();
                    location.href=history.back();
        		}else{
        			top.layer.close(index);
                    top.layer.msg("操作失败！");
        		}
        	},
        	fail:function(){
        		top.layer.close(index);
                top.layer.msg("操作失败！");
        	}
        })   
        return false;
    })

    
    
    //创建一个编辑器
    var editIndex = layedit.build('content',{
        height : 535,
        
    });
	
})
</script>
</body>
</html>